package com.qfedu.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.entity.Exercises;
import com.qfedu.entity.ResponseData;
import com.qfedu.service.ExercisesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/***
 *
 *   █████▒█    ██  ▄████▄   ██ ▄█▀       ██████╗ ██╗   ██╗ ██████╗
 * ▓██   ▒ ██  ▓██▒▒██▀ ▀█   ██▄█▒        ██╔══██╗██║   ██║██╔════╝
 * ▒████ ░▓██  ▒██░▒▓█    ▄ ▓███▄░        ██████╔╝██║   ██║██║  ███╗
 * ░▓█▒  ░▓▓█  ░██░▒▓▓▄ ▄██▒▓██ █▄        ██╔══██╗██║   ██║██║   ██║
 * ░▒█░   ▒▒█████▓ ▒ ▓███▀ ░▒██▒ █▄       ██████╔╝╚██████╔╝╚██████╔╝
 *  ▒ ░   ░▒▓▒ ▒ ▒ ░ ░▒ ▒  ░▒ ▒▒ ▓▒       ╚═════╝  ╚═════╝  ╚═════╝
 *  ░     ░░▒░ ░ ░   ░  ▒   ░ ░▒ ▒░
 *  ░ ░    ░░░ ░ ░ ░        ░ ░░ ░
 *           ░     ░ ░      ░  
 */
@RestController
public class ExercisesController {
    @Autowired
    private ExercisesService exercisesService;

    @RequestMapping("/exer/add.do")
    public ResponseData addExercises(Exercises exercises){
         ResponseData responseData = new ResponseData();
         int i = exercisesService.addExercuses(exercises);
         if(i>0){
             responseData.setCode(0);
             responseData.setMsg("添加成功");
         }
         return responseData;
    }

    @RequestMapping("/exer/select.do")
    public ResponseData<List<Exercises>> findExercisesAll(int page, int limit){
        ResponseData<List<Exercises>> listResponseData = new ResponseData<>();
        PageHelper.startPage(page,limit);
        List<Exercises> exercisesAll = exercisesService.findExercisesAll();
        PageInfo<Exercises> exercisesPageInfo = new PageInfo<>(exercisesAll);
        listResponseData.setCode(0);
        listResponseData.setCount((int) exercisesPageInfo.getTotal());
        listResponseData.setData(exercisesAll);
        return listResponseData;
    }

    @RequestMapping("/exer/delete.do")
    public ResponseData deleteExercises(int id){
        ResponseData responseData = new ResponseData();
        int i = exercisesService.delExercises(id);
        if(i>0){
            responseData.setCode(1);
            responseData.setMsg("success");
        }
        return responseData;
    }
}
